package com.iplant.wms.controller.wms;

import com.iplant.basic.controller.BasicController;
import com.iplant.wms.service.WMSService;
import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.wms.service.po.wms.WMSStock;
import com.iplant.wms.service.po.wms.WMSStockRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/WMSStockRecord")
public class WMSStockRecordController extends BasicController<WMSStockRecord> {
	private static Logger logger = LoggerFactory.getLogger(WMSStockRecordController.class);

	@Autowired
	WMSService wWMSService;

	public WMSStockRecordController() {
		super(WMSStockRecord.class);
	}





	@GetMapping("/Stock")
	public Object Stock(HttpServletRequest request) {
		Object wResult = new Object();
		try {

			BMSEmployee wLoginUser = GetSession(request);
			int wCustomerID = StringUtils.parseInt(request.getParameter("CustomerID"));
			int wSupplierID = StringUtils.parseInt(request.getParameter("SupplierID"));
			int wStockTypeID = StringUtils.parseInt(request.getParameter("StockTypeID"));
			int wStockStatus = StringUtils.parseInt(request.getParameter("StockStatus"));
			int wFactoryID = StringUtils.parseInt(request.getParameter("FactoryID"));
			int wStoreRegionID = StringUtils.parseInt(request.getParameter("StoreRegionID"));
			int wStoreID = StringUtils.parseInt(request.getParameter("StoreID"));
			int wStoreAreaID = StringUtils.parseInt(request.getParameter("StoreAreaID"));

			int wStoreShelfID = StringUtils.parseInt(request.getParameter("StoreShelfID"));
			/**
			 * 库位
			 */
			int wStoreStationID = StringUtils.parseInt(request.getParameter("StoreStationID"));
			List<Integer> wMaterialIDList = StringUtils.parseIntList(request.getParameter("MaterialID"),",");
			int wBatchRecordID = StringUtils.parseInt(request.getParameter("BatchRecordID"));
			String wBatchRecordCode= StringUtils.parseString(request.getParameter("BatchRecordCode"));
			String wProjectNo = StringUtils.parseString(request.getParameter("ProjectNo"));

			int wHasItem = StringUtils.parseInt(request.getParameter("HasItem"));

			Pagination wPagination = GetPagination(request);
			ServiceResult<List<WMSStock>> wServiceResult = wWMSService.WMS_QueryStockCountList(wLoginUser,
					wFactoryID, wStoreID, wStoreRegionID, wStoreAreaID, wStoreShelfID, wStoreStationID,
					wMaterialIDList, wBatchRecordID,wBatchRecordCode, wProjectNo, wCustomerID, wSupplierID, wStockTypeID,
					wStockStatus,wHasItem, wPagination);

			if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
				wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, wPagination.getTotalPage());
			} else {
				wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode());
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			logger.error(ex.toString());
			wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString());
		}
		return wResult;
	}



}
